/*P2P File Sharing System
Peer-to-peer(P2P) computing technology has been widely used on the Internet to exchange data. A lot of P2P file sharing systems exist and gain much popularity in nowadays.
Let's consider a simplified model of P2P file sharing system: There are many computers in the system, and they can receive data from or send data to others. To simplify the problem, let's assume that there is just ONE large file which is of our concern in the system. Some computers already have the whole file (we call them "servers" and some don't(we call them "clients". Every client needs to download the file from servers. When a client gets the WHOLE file, it becomes a server.
These computers are not always online. An online client will down load the file from all online servers. Different servers send data of different parts of the file to a client, so the client can download the file faster.
Now given the transfer speed between each pair of computers, what time is every computer online or offline, and which computers are servers at the beginning, please analyze the running of the system in a period of time.
Input
The first line contains an integer indicating the number of test cases.
For each test case:
Line 1: It contains two positive integers: n and T(n<=20, T<=1000) meaning that there are n computers in the system numbered from 1 to n, and you task is to figure out that how many percentage of the file does every computer gets after T seconds from the beginning.
Line 2: It contains two positive integers: k and S (k<=n, S<=220) meaning that at the beginning there are k servers, and the size of the file of our concern is S (KB).
Line 3: It contains k integers. It's a list of all servers'No.
Line 4 ~ n+3: These n lines form a matrix of size n*n. The j-th integer in the i-th row of the matrix represents the transfer speed (in KB/s, no more than 210) between computer i and computer j (i and j start from 1). The matrix is symmetrical and the integers on the diagonal are meaningless.
Line n+4 ~ 2n+3: Each line contains an online/offline pattern for a computer in the following format( These lines are in the ascending order of computer No.) :
t online_time 1 offline_time 1 online_time 1 offline_time 2 ... online_time t offline_time t
t is an integer no more than 10 and the time given are all non-negative integers and in ascending order. During the time between online_timei and offline_timei, the computer is online and can download data from other computers or send data to other computers.
Line 2n+4: It contains one positive integer m, representing the number of download actions in the system.
Line 2n+5 ~ 2n+m+4: Each line contains two integers representing a download action in the following format:
download_time i computer_id i
At time download_time i, the computer computer_idi starts to download the file. 0<= download_time i <=T, 1<= computer_id i <=n. These lines are given in non-descending order of time. It's guaranteed that servers never try to download the file. It's ensured that at time download_time i the computer computer_idi is online (Though it's possible that it instantly go offline after issuing a download command).
When a client starts to download, it will try to connect to all servers and download data simultaneously from online servers. The client's download speed is the sum of all connections. We assume the construction of a connection to be instant and cost no time. Only data transfer is time consuming.
When a client goes offline, unfinished download task will be saved and continued when it's online next time. If a server goes online, all computers that are currently downloading will connect to it and download data from it. What's more, when a client becomes a server, it begins to send data to clients immediately. NOTE: To simplify the problem, time used to download a file should be rounded up to integer(If the file size is 6KB and download speed is 5KB/s, the download task will cost 2 seconds instead of 1.2 seconds ----- 5KB for the first second and 1KB for the next second).
Please note that all times given above are in seconds.
Output
For each test case, the output should contain n lines, each for a computer.
The i-th line contains a percentage indicating the amount of data the i-th computer gets after T seconds from the beginning, in the format: "percentage%". The percentage should be rounded down to integer.
Sample Input
1
2 50
1 1024
1
0 10
10 0
1 0 50
1 10 40
1
10 2

1
4 500
2 200
2 3
0 1 1 1
1 0 1 1
1 1 0 1
1 1 1 0
2 0 200 300 500
1 100 200
1 200 400
1 301 500
2
0 1
301 4
Sample Output
100%
29%
100%
100%
100%
99%
Hint
There are 2 computers. The file size is 1024 KB and Computer 1 is a server at the beginning. At time 10, computer 2 start to download that file from computer 1
until it goes offline at time 40. Totally 10KB/s * 30s = 300KB is downloaded. 300/1024 ≈ 29%.
题目大意：
t组case。
n(n <= 20)台电脑，T(T <= 1000)：模拟过程的总时间（这才是进行模拟的关键轴）。（单位：second）
k表示有k台电脑初始时作为服务器直接提供文件下载，S：下载文件的大小（在模拟过程中只有一个文件可供下载）。（单位：kb）
此行有k个数：表示作为服务器的k台电脑的编号id（或者说标记名称）。
一个n*n的对阵矩阵，matrix[i][j]的值表示编号为i和编号为j的电脑互相之间下载上传速度（带宽不被分享，即恒定），主对角线均为0，因为自身无传输速度。
接下来n行：第i行对应编号为i的电脑，每行第一个数为t，表示第i台电脑有t段在线时间，接下来2t个数，分别表示第t段时间的开始时间点和结束时间点（即第i台电脑的上线时间和下线时间，时间段为左闭右开，即下线时间点不提供下载上传服务）。
m表示有m次下载操作。（因为每台电脑的下载操作只需执行一次，便会一直在时间轴界限(<=T)内一直执行，又因为没有终止下载操作，所以对于每台电脑来说，最多只会有一个执行操作，所以虽然m未给数据范围，但是显然，m<=n）
m行：每行第一个数表示下载开始时间点t(i)，第二个数表示开始下载的电脑c(i)。
（保证初始为服务器的电脑不会被要求执行下载的命令）
（虽然一台电脑被执行了下载命令，可是若它不在线，也不能下载，只是出于挂起状态，等待上线）
（当某台电脑的文件下载完成度达到100%以后，自动变为服务器，开始上传，不再执行下载操作）
（客户端电脑会从所有服务器同时进行下载）
（因为下载时间是上取整，所以按时间轴模拟的话，最后文件完成度要进行下取整，互逆操作啊~）
*/
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;

int n,T,k,S;//机数，时间轴长度，初始服务器数量，文件大小
bool ser[25];//标记某台电脑是否为服务器
int mat[25][25];//传输速度矩阵
int t;//在线时间段数
bool TIME[25][1005];//利用离散化思想通过标记数组记录每台电脑在线时间点
int on,off;
int m;//操作数
bool click[25];//当有下载命令下达时，某台电脑才会变为客户端，该标记数组用以确定某台电脑是否被激活变成进行下载的客户端
bool com[1005];//所谓时间标记数组，用以记录时间轴上哪一点有激活操作发生
int cont[25];//某台电脑上“关键文件”的剩余需下载量（初始为S，服务器为0）

struct command//该结构体用以扫描时间标记数组以确定某特定时间点哪一台电脑被激活
{
    int t,c;//表示t时间点第c台电脑被激活
} co[30];

void solve()
{
    scanf("%d%d",&n,&T);
    scanf("%d%d",&k,&S);
    for(int i = 1; i <= n; i++) //初始化时间轴
        for(int j = 0; j <= T; j++)
            TIME[i][j] = 0;
    for(int i = 0; i <= T; i++) //初始化时间标记数组
        com[i] = 0;//command seq init
    for(int i = 1; i <= n; i++) //各种init
    {
        ser[i] = 0;
        cont[i] = S;
        click[i] = 0;
        co[i].t = -1;//时间轴从0开始，将命令操作初始存在时间改为-1以防WA
    }
    for(int i = 1; i <= k; i++) //which is server
    {
        int a;
        scanf("%d",&a);//确定初始服务器
        ser[a] = 1;
        cont[a] = 0;//规范化服务器的文件剩余量
    }
    for(int i = 1; i <= n; i++) //trans velocity to each other
        for(int j = 1; j <= n; j++)
            scanf("%d",&mat[i][j]);//读入矩阵

    for(int i = 1; i <= n; i++) //读入第i台电脑的在线时间段
    {
        scanf("%d",&t);//t segments
        for(int j = 1; j <= t; j++)
        {
            int a,b;
            scanf("%d%d",&a,&b);
            for(int z = a; z <= b - 1; z++)
                TIME[i][z] = 1;//离散化思想储存第i台的在线时间点
        }
    }
    scanf("%d",&m);//m operation.
    for(int i = 1; i <= m; i++)
    {
        scanf("%d%d",&co[i].t,&co[i].c);//第t时间第c台电脑被激活
        com[co[i].t] = 1;
    }
    for(int i = 0; i <= T; i++) //时间轴上扫描
    {
        //key..judge
        if(com[i] == 1)//如果该时间点有激活操作发生
        {
            for(int j = 1; j <= n; j++) //搜索对应激活操作的是哪台电脑
                if(co[j].t == i)
                    click[co[j].c] = 1;//标记激活
        }
        //handle
        for(int j = 1; j <= n; j++) //第j台电脑
        {
            if(click[j] == 1 && TIME[j][i] == 1 && ser[j] == 0)//已激活，在线，非服务器
            {
                for(int z = 1; z <= n; z++) //扫描所有电脑和第j台电脑的关系
                {
                    if(ser[z] == 1)//如果z是服务器
                    {
                        if(TIME[z][i] == 1)//z在线，i时刻
                        {
                            cont[j] -= mat[j][z];//那么就在i时刻，z传给j，mat[j][z]大小的文件块
                        }
                    }
                }
            }
        }
        for(int j = 1; j <= n; j++) //每秒过后扫描是否有新的电脑变成服务器提供下载，关键！
        {
            if(cont[j] <= 0)
            {
                cont[j] = 0;
                ser[j] = 1;
            }
        }
    }
    for(int i = 1; i <= n; i++)
    {
        double rate = (double)(S - cont[i]) * 100 / S;//输出完成度，用下取整（对应题目中上取整）
        printf("%.0lf%%\n",floor(rate));
    }
}
int main()
{
    int ca;
    while(cin >> ca)
    {
        for(int i = 0; i < ca; i++)
            solve();
    }

}
